package com.ibm.risk.irmp.workflow.client.flowable.api;

import com.ibm.risk.irmp.workflow.client.flowable.ApiClient;
import com.ibm.risk.irmp.workflow.client.flowable.model.BatchPartResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.BatchResponse;
import com.ibm.risk.irmp.workflow.client.flowable.model.DataResponseBatchResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.util.UriComponentsBuilder;

import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Component("com.ibm.risk.irmp.flowable.api.BatchesApi")
public class BatchesApi {
    private ApiClient apiClient;

    public BatchesApi() {
        this(new ApiClient());
    }

    @Autowired
    public BatchesApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Delete a batch
     *
     * <p><b>204</b> - Indicates the batch was found and has been deleted. Response-body is intentionally empty.
     * <p><b>404</b> - Indicates the requested batch was not found.
     * @param batchId The batchId parameter
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public void deleteBatch(String batchId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'batchId' is set
        if (batchId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'batchId' when calling deleteBatch");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("batchId", batchId);
        String path = UriComponentsBuilder.fromPath("/management/batches/{batchId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<Void> returnType = new ParameterizedTypeReference<Void>() {};
        apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get a single batch
     *
     * <p><b>200</b> - Indicates the batch exists and is returned.
     * <p><b>404</b> - Indicates the requested batch does not exist.
     * @param batchId The batchId parameter
     * @return BatchResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public BatchResponse getBatch(String batchId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'batchId' is set
        if (batchId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'batchId' when calling getBatch");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("batchId", batchId);
        String path = UriComponentsBuilder.fromPath("/management/batches/{batchId}").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<BatchResponse> returnType = new ParameterizedTypeReference<BatchResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get the batch document
     *
     * <p><b>200</b> - Indicates the requested batch was found and the batch document has been returned. The response contains the raw batch document and always has a Content-type of application/json.
     * <p><b>404</b> - Indicates the requested batch was not found or the job does not have a batch document. Status-description contains additional information about the error.
     * @param batchId The batchId parameter
     * @return String
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public String getBatchDocument(String batchId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'batchId' is set
        if (batchId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'batchId' when calling getBatchDocument");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("batchId", batchId);
        String path = UriComponentsBuilder.fromPath("/management/batches/{batchId}/batch-document").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<String> returnType = new ParameterizedTypeReference<String>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * Get the batch part document
     *
     * <p><b>200</b> - Indicates the requested batch part was found and the batch part document has been returned. The response contains the raw batch part document and always has a Content-type of application/json.
     * <p><b>404</b> - Indicates the requested batch part was not found or the job does not have a batch part document. Status-description contains additional information about the error.
     * @param batchPartId The batchPartId parameter
     * @return String
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public String getBatchPartDocument(String batchPartId) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'batchPartId' is set
        if (batchPartId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'batchPartId' when calling getBatchPartDocument");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("batchPartId", batchPartId);
        String path = UriComponentsBuilder.fromPath("/management/batch-parts/{batchPartId}/batch-part-document").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        final String[] accepts = { };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<String> returnType = new ParameterizedTypeReference<String>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List batches
     *
     * <p><b>200</b> - Indicates the requested batches were returned.
     * <p><b>400</b> - Indicates an illegal value has been used in a url query parameter. Status description contains additional details about the error.
     * @param id Only return batch with the given id
     * @param batchType Only return batches for the given type
     * @param searchKey Only return batches for the given search key
     * @param searchKey2 Only return batches for the given search key2
     * @param createTimeBefore Only return batches created before the given date
     * @param createTimeAfter Only batches batches created after the given date
     * @param completeTimeBefore Only return batches completed before the given date
     * @param completeTimeAfter Only batches batches completed after the given date
     * @param status Only return batches for the given status
     * @param tenantId Only return batches for the given tenant id
     * @param tenantIdLike Only return batches like given search key
     * @param withoutTenantId If true, only returns batches without a tenantId set. If false, the withoutTenantId parameter is ignored.
     * @return DataResponseBatchResponse
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public DataResponseBatchResponse listBatches(String id, String batchType, String searchKey, String searchKey2, OffsetDateTime createTimeBefore, OffsetDateTime createTimeAfter, OffsetDateTime completeTimeBefore, OffsetDateTime completeTimeAfter, String status, String tenantId, String tenantIdLike, Boolean withoutTenantId) throws RestClientException {
        Object postBody = null;

        String path = UriComponentsBuilder.fromPath("/management/batches").build().toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "id", id));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "batchType", batchType));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "searchKey", searchKey));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "searchKey2", searchKey2));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createTimeBefore", createTimeBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "createTimeAfter", createTimeAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "completeTimeBefore", completeTimeBefore));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "completeTimeAfter", completeTimeAfter));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", status));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantId", tenantId));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "tenantIdLike", tenantIdLike));
        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "withoutTenantId", withoutTenantId));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<DataResponseBatchResponse> returnType = new ParameterizedTypeReference<DataResponseBatchResponse>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
    /**
     * List batch parts
     *
     * <p><b>200</b> - Indicates the requested batch parts were returned.
     * <p><b>400</b> - Indicates an illegal value has been used in a url query parameter. Status description contains additional details about the error.
     * @param batchId The batchId parameter
     * @param status Only return batch parts for the given status
     * @return List&lt;BatchPartResponse&gt;
     * @throws RestClientException if an error occurs while attempting to invoke the API
     */
    public List<BatchPartResponse> listBatchesPart(String batchId, String status) throws RestClientException {
        Object postBody = null;

        // verify the required parameter 'batchId' is set
        if (batchId == null) {
            throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'batchId' when calling listBatchesPart");
        }

        // create path and map variables
        final Map<String, Object> uriVariables = new HashMap<String, Object>();
        uriVariables.put("batchId", batchId);
        String path = UriComponentsBuilder.fromPath("/management/batches/{batchId}/batch-parts").buildAndExpand(uriVariables).toUriString();

        final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
        final HttpHeaders headerParams = new HttpHeaders();
        final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

        queryParams.putAll(apiClient.parameterToMultiValueMap(null, "status", status));

        final String[] accepts = {
            "application/json"
        };
        final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
        final String[] contentTypes = { };
        final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);

        String[] authNames = new String[] { "basicAuth" };

        ParameterizedTypeReference<List<BatchPartResponse>> returnType = new ParameterizedTypeReference<List<BatchPartResponse>>() {};
        return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
    }
}
